{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "\n",
    "tf.compat.v1.disable_eager_execution()\n",
    "\n",
    "#v1 = tf.constant([1,2,3,4,5])\n",
    "#v2 = tf.constant([2,1,5,3,4])\n",
    "#v_add = tf.add(v1,v2)\n",
    "#sess = tf.compat.v1.Session()\n",
    "#print(sess.run(v_add))\n",
    "\n",
    "x = tf.Variable(0.)\n",
    "y = tf.Variable(1.)\n",
    "# x =  x + y\n",
    "add_op = x.assign(x + y)\n",
    "# y = y / 2\n",
    "div_op = y.assign(y / 2)\n",
    "with tf.compat.v1.Session() as sess2:  # 打开会话\n",
    "    sess2.run(tf.compat.v1.global_variables_initializer()) # 初始会话\n",
    "    for iteration in range(50):\n",
    "        sess2.run(add_op)\n",
    "        sess2.run(div_op)\n",
    "    print(x.eval()) # x为variable对象，用eval函数调取真实值 或者：sess.eval(x)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
